jQuery.fn.tucao = function(a) {
	a = jQuery.extend( {
		auto_play : true,
		play_delay : 1000,
		play_tick : 2500,
		opacity : 0.8,
		buffer : 3,
		object_type : "comic",
		object_id : 0,
		total_tucao : 0,
		c_id : 0,
		b_id : 0,
		p_id : 0,
		callback : function() {
		},
		tucao_id : 0
	}, a || {});
	var c = '<div style="width: 750px;" class="toso_button">';
	c += '<div class="toso_button_content">';
	c += '<span class="bg_yellow"><a href="javascript:;" class="btn_bg"></a>';
	c += '<div class="toso_bg_hover" style="display:none;" value="0"><a href="javascript:;" class="yellow" value="0">\u9ec4\u3000\u3000\u8272</a><a href="javascript:;" class="pink" value="1">\u7c89\u3000\u3000\u8272</a><a href="javascript:;" class="blue" value="2">\u84dd\u3000\u3000\u8272</a><a href="javascript:;" class="no" value="3">\u65e0\u8fb9\u900f\u660e</a><a href="javascript:;" class="no_white" value="4">\u65e0\u8fb9\u767d\u8272</a><a href="javascript:;" class="no_black" value="5">\u65e0\u8fb9\u9ed1\u8272</a></div>';
	c += "</span>";
	c += '<span class="font_black"><a href="javascript:;" class="btn_font"></a>';
	c += '<div class="toso_font_hover" style="display:none;" value="0"><a href="javascript:;" class="yellow" value="2">\u9ec4\u3000\u8272</a><a href="javascript:;" class="red" value="3">\u7ea2\u3000\u8272</a><a href="javascript:;" class="green" value="4">\u7eff\u3000\u8272</a><a href="javascript:;" class="blue" value="5">\u84dd\u3000\u8272</a><a href="javascript:;" class="white" value="1">\u767d\u3000\u8272</a><a href="javascript:;" class="black" value="0">\u9ed1\u3000\u8272</a></div>';
	c += '</span><span class="textarea_left"></span><span class="textarea_right">';
	c += '<input type="text" style="width: 224px;" class="textarea input_tucao" value="\u8fd9\u91cc\u53ef\u4ee5\u8f93\u5165\u4f60\u60f3\u8981\u5410\u69fd\u7684\u8bdd\u54e6\uff01" onclick="if(this.value==\'\u8fd9\u91cc\u53ef\u4ee5\u8f93\u5165\u4f60\u60f3\u8981\u5410\u69fd\u7684\u8bdd\u54e6\uff01\') this.value=\'\'" maxlength="20"/></span><span><a href="javascript:;" class="btn_toso"></a></span>';
	c += '<span><a href="javascript:;" class="btn_show" title="\u9690\u85cf\u5410\u69fd/\u663e\u793a\u5410\u69fd"></a></span><span></span>';
	c += '<span class="explain"><span class="total_tucao">\u8d76\u5feb\u6765\u5410\u69fd\u5427\uff01</span></span>';
	c += "</div>";
	c += "</div>";
	if (a.tucao_id > 0) {
		a.play_delay = 0
	}
	function d(g, e) {
		$(g).unbind().bind("click", function() {
			$(g).blur();
			$(e).fadeIn("fast");
			if ($(g).data("time")) {
				clearTimeout($(g).data("time"))
			}
			if ($(e).data("time")) {
				clearTimeout($(e).data("time"))
			}
			return false
		}).bind("mouseleave", function() {
			hidequcikmenu = setTimeout(function() {
				$(e).fadeOut("fast")
			}, 200);
			$(g).data("time", hidequcikmenu)
		});
		$(e).unbind().bind("mouseleave", function() {
			hidequcikmenu = setTimeout(function() {
				$(e).fadeOut("fast")
			}, 200);
			$(e).data("time", hidequcikmenu)
		}).bind("mouseenter", function() {
			if ($(g).data("time")) {
				clearTimeout($(g).data("time"))
			}
			if ($(e).data("time")) {
				clearTimeout($(e).data("time"))
			}
		}).find("a").click(function() {
			$(this).blur();
			$(e).fadeOut("fast");
			return false
		})
	}
	return this
			.each(function() {
				var I = get_user_setting();
				var E = jQuery(this);
				
				var g = E.width();
				var j = E.height();
				var af = $(c);
				var y = af.find(".toso_bg_hover");
				var F = af.find(".toso_font_hover");
				var ao = af.find(".btn_bg");
				var V = af.find(".btn_font");
				var A = af.find(".btn_toso");
				var B = af.find(".btn_pre");
				var ah = af.find(".btn_next");
				var z = af.find(".btn_stop");
				var J = af.find(".btn_show");
				var k = af.find(".input_tucao");
				var Z = af.find(".total_tucao");
				var r = true;
				var C = true;
				var q = false;
				var s = false;
				var ak = parseInt(g * j / 3 / (15000));
				if (ak < 2) {
					ak = 2
				}
				var ag = null;
				var aa = null;
				var K = [];
				var o = r;
				var D = 10;
				var N = null;
				var u = 19;
				var X = [ "\u5171\u67090\u4e2a\u5410\u69fd\uff0c\u6b22\u8fce\u5927\u5bb6\u5410\u69fd" ];
				var Q = 0;
				var G = false, m = false;
				var R;
				var am;
				var U;
				var ae;
				
				if (g < 200 || j < 200) {
					E
							.after('<div class="toso_button zoom auto"><div class="toso_button_content" style="line-height:45px;color:#333;">\u56fe\u7247\u5bbd\u5ea6\u5c0f\u4e8e200\u6216\u8005\u9ad8\u5ea6\u5c0f\u4e8e200\u5219\u4e0d\u5f00\u653e\u5410\u69fd\u529f\u80fd</div></div>');
					return
				}
				$(document).bind("keydown", function(ar) {
					ar = ar || window.event;
					var at = ar.which || ar.keyCode;
					switch (at) {
					case 67:
						if (!shortcut_check_input() && !s && !ar.ctrlKey) {
							if (C) {
								ai()
							} else {
								W()
							}
						}
						break
					}
				});
				y
						.find("a")
						.click(
								function() {
									v = $(this).attr("value");
									y.attr("value", v);
									ao.parent().attr("class",
											"bg_" + $(this).attr("class"));
									set_user_setting("tucao_b", v)
									return false
								});
				d(ao, y);
				F
						.find("a")
						.click(
								function() {
									v = $(this).attr("value");
									F.attr("value", v);
									V
											.parent()
											.attr(
													"class",
													"font_"
															+ $(this)
																	.attr(
																			"class"));
									set_user_setting("tucao_f", v)
									return false
								});
				d(V, F);
				A.click(function(ar) {
					$(this).blur();
					O(ar);
					return false
				});
								
				z.click(function() {
					$(this).blur();
					if (r) {
						H()
					} else {
						M()
					}
					return false
				});
				J.click(function() {
					$(this).blur();
					if (C) {
						ai()
					} else {
						W()
					}
					return false
				});
				
				if (I != null && I.tucao == "0") {
					ai()
				}
				
				if (a.auto_play) {
					setTimeout(function() {
						ac()
					}, a.play_delay)
				}
				function ac() {
					clearTimeout(ae);
					if (r && C && a.total_tucao > 0) {
						l()
					}
				}
				
				
				if (X.length > 1) {
					setInterval(function() {
						if (Q >= X.length) {
							Q = 0
						}
						Z.html(X[Q]);
						Q++
					}, 3000)
				}
				
				E.after(af);
				var al = null;
				function Y(ar) {
					X[0] = "\u5171\u6709"
						+ ar
						+ "\u4e2a\u5410\u69fd\uff0c\u6b22\u8fce\u5927\u5bb6\u5410\u69fd"
					a.total_tucao = ar;
					Z.html(X[0]);
				}
				function ab() {
					K = [];
					ag = aa = null;
					N = get_user();
					D = 10
				}
				function M() {
					if (!C) {
						W()
					}
					o = r;
					r = true;
					z.addClass("btn_stop").removeClass("btn_play");
					ac()
				}
				function H() {
					o = r;
					r = false;
					z.addClass("btn_play").removeClass("btn_stop")
				}
				function W() {
					set_user_setting("tucao", "1");
					C = true;
					J.addClass("btn_show").removeClass("btn_hide");
					if (o) {
						M()
					}
					$(".toso_dialogue").show()
				}
				function ai() {
					set_user_setting("tucao", "0");
					C = false;
					o = r;
					J.addClass("btn_hide").removeClass("btn_show");
					if (o) {
						H()
					}
					$(".toso_dialogue").hide()
				}
				function x(au) {
					var at = $('<span style="display:none">' + au + "</span>");
					$("body").append(at);
					var ar = at.width();
					at.remove();
					return ar
				}
				function O(ay) {
					N = get_user();
					if (N == null) {
						login_ajax();
						return
					}
					if (q) {
						return
					}
					if (!C) {
						W()
					}
					if (r) {
						H()
					}
					var az = k.val();
					if (az == null
							|| az.length == 0
							|| az == "\u8fd9\u91cc\u53ef\u4ee5\u8f93\u5165\u4f60\u60f3\u8981\u5410\u69fd\u7684\u8bdd\u54e6\uff01") {
						popMsg("吐槽内容不能为空哦");
						return
					}
					if (az.length > 20) {
						popMsg("吐槽内容不能超出20个字符哦");
						return
					}
					q = s = true;
					var ar = y.attr("value");
					var aC = F.attr("value");
					var au = x(az);
					var aD = (parseInt(au / 250) + 1) * 20 + 10;
					au += 12;
					if (au > 250) {
						au = 250
					}
					$(".toso_dialogue").hide();
					E
							.append('<div class="send_over" style="z-index:9999;position:absolute;top:0;left:0;width:'
									+ g
									+ "px;height:"
									+ j
									+ 'px;background-color:#000;filter:alpha(opacity=30); opacity:0.3"></div>');
					var av = mouseCoords(ay);
					var aw = E.offset();
					var aB = '<div id="tucao_cursor" class="toso_cursor" style="top:'
							+ av.y + "px;left:" + av.x + 'px"></div>';
					var ax = function(aF) {
						av = mouseCoords(aF);
						var aE = av.x - aw.left;
						var aH = av.y - aw.top;
						var aG = $("#tucao_cursor");
						if (aE < 0 || aE > g || aH < 0 || aH > j) {
							aG.addClass("toso_cursor_no")
						} else {
							aG.removeClass("toso_cursor_no")
						}
						aG.css("top", av.y).css("left", av.x)
					};
					var at = function(aE) {
						aE = aE || window.event;
						var aF = aE.which || aE.keyCode;
						if (aF == 27) {
							$("body").unbind("click", aA).unbind("mousemove",
									ax);
							$(document).unbind("keydown", at);
							$("#tucao_cursor").remove();
							E.find(".send_over").remove();
							$(".toso_dialogue").show();
							q = s = false
						}
					};
					var aA = function(aF) {
						av = mouseCoords(aF);
						var aE = av.x - aw.left;
						var aG = av.y - aw.top;
						
						$("body").unbind("click", aA).unbind("mousemove", ax);
						$(document).unbind("keydown", at);
						$("#tucao_cursor").remove();
						E.find(".send_over").remove();
						if (aE < 0 || aE > g || aG < 0 || aG > j) {
							popMsg("吐槽的位置不对哦");
							S(ak, "next");
							return
						}
						n();
						$
								.ajax( {
									url : domain_url + "/TcomicTucao/saveTucao.do",
									type : "POST",
									data : {
										x : aE,
										y : aG,
										w : au,
										h : aD,
										content : az,
										color : aC,
										back : ar,
										b_id:a.b_id,
										c_id:a.c_id,
										p_id:a.p_id
									},
									cache : false,
									success : function(result) {
										var aH = eval(result);
										popMsg(aH[0].message);
										Y(parseInt(a.total_tucao) + 1);
										S(ak, "next");
									},
									error : function() {
										q = s = false;
										showMsg("\u901a\u8baf\u9519\u8bef\u8bf7\u7a0d\u540e\u518d\u8bd5");
									}
								})
					};
					$(document).bind("keydown", at);
					$("body").append(aB);
					$("body").bind("mousemove", ax).bind("click", aA)
				}
				function l() {
					S(ak, "next");
				}
				
				function an(ar) {
					if (N != null && N.id == ar.user_id) {
						return true
					}
					return false
				}
				function w(at) {
					yy = at.y - u;
					D++;
					var av = x(at.content);
					av += at.back > 2 ? 20 : 22;
					min_w = parseInt(av / 19) + 16;
					min_w = min_w < 22 ? 22 : min_w;
					av = av > 250 ? 250 : av;
					var ar = an(at);
					var aw = "";
					aw = at.nickname + " \u5410\u69fd\u4e8e " + at.time;
					
					font_color = [ "black", "white", "yellow", "red", "green",
							"blue" ];
					bg_color = [ "yellow", "pink", "blue", "no", "no_white",
							"no_black" ];
					opacity = at.back > 2 ? "filter:alpha(opacity=100); opacity:1;"
							: "filter:alpha(opacity=" + a.opacity * 100
									+ "); opacity:" + a.opacity + ";";
					if (ar === false) {
						el = $('<div id="tucao_'
								+ at.tucao_id
								+ '" style="'
								+ opacity
								+ "display:none;float:left;width: "
								+ at.width
								+ "px; left: "
								+ at.x
								+ "px; top: "
								+ yy
								+ "px;z-index:"
								+ D
								+ ';" class="toso_dialogue"><div class="toso_content toso_bg_'
								+ bg_color[at.back] + " toso_font_"
								+ font_color[at.color] + '" title="' + aw
								+ '">' + at.content + "</div></div>")
					} else {
						html = '<div id="tucao_' + at.tucao_id + '" style="'
								+ opacity + "display:none;float:left;width: "
								+ at.width + "px; left: " + at.x + "px; top: "
								+ yy + "px;z-index:" + D
								+ ';" class="toso_dialogue">';
						html += '<div class="toso_title handler" style="display:none;"><a href="###" class="close"></a></div>';
						html += '<div class="toso_content toso_font_'
								+ font_color[at.color] + " toso_bg_"
								+ bg_color[at.back] + '" title="' + aw
								+ '"><p>' + at.content + "</p>";
						html += "</div>";
						html += "</div>";
						el = $(html)
					}
					el.click(function() {
						$(this).css("z-Index", D++)
					});
					E.append(el);
					el.fadeIn();
					if (a.tucao_id == at.tucao_id) {
						var au = el.find("div.toso_content").css("padding",
								"2px 4px 6px");
						setTimeout(function() {
							au.css("border", "2px solid #ff0000")
						}, 300);
						setTimeout(function() {
							au.css("border", "2px solid #7E7E7E")
						}, 600);
						setTimeout(function() {
							au.css("border", "2px solid #ff0000")
						}, 900);
						setTimeout(function() {
							au.css("border", "2px solid #7E7E7E")
						}, 1200);
						setTimeout(function() {
							au.css("border", "2px solid #ff0000")
						}, 1500);
						setTimeout(function() {
							au.css("border", "1px solid #7E7E7E").css(
									"padding", "3px 5px 7px")
						}, 1800)
					}
					if (ar) {
						el.resizable( {
							containment : "parent",
							handles : "w, e ,se",
							autoHide : true,
							maxWidth : av,
							minWidth : min_w,
							maxHeight : 400,
							start : function() {
								H()
							},
							resize : function(ax, ay) {
								$(this).css("height", "auto");
								$(this).find(".toso_content").css("height",
										"auto")
							},
							stop : function(ax, ay) {
								$(this).find(".toso_content").css("height",
										"1%");
								aq(at.tucao_id, $(this).width(), $(this)
										.height());
								if (o) {
									M()
								}
							}
						});
						el.draggable( {
							handle : "div.toso_title",
							containment : "parent",
							opacity : a.opacity * 0.8,
							start : function() {
								H()
							},
							stop : function(ax, ay) {
								var az = $(this).position();
								L(at.tucao_id, az.left, az.top + u);
								if (o) {
									M()
								}
							}
						});
						if (at.back == 3) {
							el.hover(function() {
								$(this).find("div.handler").show();
								$(this).find("div.toso_content").addClass(
										"toso_bg_no_hover")
							}, function() {
								$(this).find("div.handler").hide();
								$(this).find("div.toso_content").removeClass(
										"toso_bg_no_hover")
							})
						} else {
							el.hover(function() {
								$(this).find("div.handler").show()
							}, function() {
								$(this).find("div.handler").hide()
							})
						}
						el
								.find(".close")
								.click(
										function() {
											$
													.confirmDialog(
															{
																msg : "\u786e\u8ba4\u8981\u5220\u9664\u5417\uff1f"
															}, function() {
																ad(at.tucao_id)
															})
										})
					}
				}
				function ap(ar) {
					$("#tucao_" + ar.tucao_id).remove()
				}
				function n() {
					$(".toso_dialogue").remove()
				}
				function S(ar, at) {
					G = m = false;					
					$
							.ajax( {
								url : domain_url + "/TcomicTucao/getTucao.do",
								data : {
									b_id:a.b_id,
									c_id:a.c_id,
									p_id:a.p_id
								},
								cache : false,
								error : function() {
									q = false;
									H()
								},
								success : function(result) {
									au = eval(result);
									if (au[0].code <= 0) {
										showMsg(au[0].message);
										q = false;
										return
									}
									Y(au[0].total_count);
									
									if (at == "next") {
										if (au[0].list.length == 0) {
											H()
										} else {
											K = t(K, au[0].list);											
											count = $(".toso_dialogue").length;
											for (i = 0; i < K.length; i++) {
												w(K[i]);
											}
											q = false
										}
									}									
								}
							})
				}
				function p(at, ar) {
					var av = at.length + ar.length - a.buffer * ak;
					var au = [];
					for (i = 0; i < ar.length; i++) {
						au.push(ar[i])
					}
					if (av > 0) {
						for (i = 0; i < at.length; i++) {
							if (i < at.length - av) {
								au.push(at[i])
							}
						}
					} else {
						for (i = 0; i < at.length; i++) {
							au.push(at[i])
						}
					}
					return au
				}
				function t(at, ar) {
					var av = at.length + ar.length - a.buffer * ak;
					var au = [];
					if (av > 0) {
						for (i = 0; i < at.length; i++) {
							if (i >= av) {
								au.push(at[i])
							}
						}
					} else {
						for (i = 0; i < at.length; i++) {
							au.push(at[i])
						}
					}
					for (i = 0; i < ar.length; i++) {
						au.push(ar[i])
					}
					return au
				}
				function T(ar) {
					for ( var at in K) {
						if (K[at].tucao_id.toString() == ar.toString()) {
							return K[at]
						}
					}
					return null
				}
			})
};
function shortcut_check_input() {
	if (typeof document.activeElement != "undefined") {
		if (typeof document.activeElement.tagName != "undefined") {
			var a = document.activeElement.tagName.toUpperCase();
			if (a == "INPUT" || a == "TEXTAREA") {
				return true
			}
		}
	}
	return false
}
function mouseCoords(a) {
	if (a.pageX || a.pageY) {
		return {
			x : a.pageX,
			y : a.pageY
		}
	}
	return {
		x : a.clientX + document.body.scrollLeft - document.body.clientLeft,
		y : a.clientY + document.body.scrollTop - document.body.clientTop
	}
}
function getUrlParam(a) {
	nk = "";
	var c = new RegExp("(^|&)" + a + "=([^&]*)(&|$)");
	var d = window.location.search.substr(1).match(c);
	if (d != null) {
		return unescape(d[2])
	}
	return nk
};
